//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

using LitwareHR.PrivateApp.Presenters.ConfigCusto;
using System.Collections.Generic;

public partial class ConfigCusto_ManageUserRoles : BasePage, IManageUserRolesView
{
    private ManageUserRolesPresenter _presenter;
    private ManageUserRolesPresenter Presenter
    {
        get
        {
            return _presenter;
        }
    }

    protected override void OnInitComplete(EventArgs e)
    {
        base.OnInitComplete(e);
        _presenter = new ManageUserRolesPresenter(this);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Presenter.OnViewLoaded(Helpers.TenantAlias, Request.QueryString["username"]);
        }
    }

    protected void RoleCheckBoxList_SelectedIndexChanged(object sender, EventArgs e)
    {
        List<string> list = new List<string>();
        foreach (ListItem item in RoleCheckBoxList.Items)
        {
            if (item.Selected)
                list.Add(item.Text);
        }

        Presenter.OnRoleSelectionChanged(Helpers.TenantAlias, list.ToArray(), Request.QueryString["username"]);
    }

    public void ShowAllRoles(string[] roleNames)
    {
        RoleCheckBoxList.DataSource = roleNames;
        RoleCheckBoxList.DataBind();
    }

    public void SelectUserRoles(string[] roleNamesToSelect)
    {
        foreach (string role in roleNamesToSelect)
        {
            RoleCheckBoxList.Items.FindByText(role).Selected = true;
        }
    }
}
